<?php
/**
 * CreateTime: 2022/9/21 14:49
 */

namespace App\Service\Approval\ApprovalContract;

use App\Consts\Approval\ApprovalSubmitTypeConsts;
use App\Consts\ContractConsts\NewContractApprovalStatus;
use App\Models\NewContract\ContractModel;
use App\Service\Approval\DingTalkApprovalInterFace;

class ApprovalContract implements DingTalkApprovalInterFace
{

    public function approvalStart($processInstanceId, $sourceId, $processStatus)
    {
        $contractModel = new ContractModel();
        $status = $contractModel->getContractInfo($sourceId,'contract_status');
        if($status['contract_status']!=NewContractApprovalStatus::CONTRACT_APPROVAL_TO_DD_HT){
            return false;
        }
        // 修改合同审批状态为审批中
        $contractModel->editContract($sourceId,[
            'contract_status' =>NewContractApprovalStatus::CONTRACT_APPROVAL_SSZ
        ]);
    }

    public function approvalAgreeEnd($processInstanceId, $sourceId, $processStatus)
    {
        $contractModel = new ContractModel();
        $status = $contractModel->getContractInfo($sourceId,'contract_status');
        if($status['contract_status']!=NewContractApprovalStatus::CONTRACT_APPROVAL_SSZ){
            return false;
        }
        // 修改合同状态为待送签
        ($contractModel)->editContract($sourceId,[
            'contract_status' =>NewContractApprovalStatus::CONTRACT_APPROVAL_DQS
        ]);
    }

    public function approvalRefuseEnd($processInstanceId, $sourceId, $processStatus)
    {
        $contractModel = new ContractModel();
        $status = $contractModel->getContractInfo($sourceId,'contract_status');
        if($status['contract_status']!=NewContractApprovalStatus::CONTRACT_APPROVAL_SSZ){
            return false;
        }
        // 修改合同状态为已退回
        // 修改合同审批状态为审批中
        ($contractModel)->editContract($sourceId,[
            'contract_status' =>NewContractApprovalStatus::CONTRACT_APPROVAL_ZF
        ]);
    }
}